package com.zg.nacos.task;

import com.zg.nacos.domain.bo.InstanceInfo;
import com.zg.nacos.domain.entity.MicroNacos;
import com.zg.nacos.service.MicroNacosService;
import com.zg.nacos.service.NacosService;
import com.zg.nacos.sys.ActiveStatusEnum;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>Description: </p>
 *
 * @author zhanfeng.liang
 * @since 2025/6/28 10:11
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class MicroNacosTask {

    private final MicroNacosService microNacosService;

    private final NacosService nacosService;

    @Scheduled(cron = "30 * * * * ?")
    public void startAuto(){
        List<MicroNacos> list=microNacosService.listAutoPre();

        list.forEach(t->{
            boolean f =nacosService.register(t);
            if(f){
                t.setActiveStatus(ActiveStatusEnum.ACTIVE.getCode());
                microNacosService.edit(t);
            }

        });
    }
}
